<template>
  <!-- 发出的评论 -->
  <div class="myoutput">
    <div class="content" v-if="sendComment.length > 0">
      <div class="item" v-for="item in sendComment" :key="item.id">
        <div class="left">
          <!-- <p class="commentContent"><span>贝贝回复我的评论：</span>{{item.parentName}}</p> -->
          <p
            class="myComment"
            v-if="item.parentUserName === null && item.lastUserName === null"
          >
            我的评论：{{ item.commentName }}
          </p>
          <p class="myComment" v-else-if="item.parentUserName !== null">
            我回复了{{ item.parentUserName }}的评论：{{ item.commentName }}
          </p>
          <p class="myComment" v-else-if="item.lastUserName !== null">
            {{ item.lastUserName }}回复了我的评论：{{ item.lastCommentName }}
          </p>
          <div class="bottom">
            <div class="bottomLeft">
              <span class="spanStyle"></span>
              <span class="projectName" v-if="item.type === 1"
                >项目：{{ item.projectName }}</span
              >
              <span class="projectName" v-else-if="item.type === 2"
                >任务：{{ item.taskName }}</span
              >
              <span class="projectName" v-else-if="item.type === 3"
                >评论：我是评论标题</span
              >
              <span class="projectName" v-else-if="item.type === 4"
                >任务结果：我是任务结果标题</span
              >
              <span class="projectName" v-else>教学资料：我是教学资料标题</span>
              <span
                :class="
                  item.taskPriority <= 100
                    ? 'LvOne'
                    : item.taskPriority > 100 && item.taskPriority <= 200
                    ? 'LvTwo'
                    : 'LvThree'
                "
                >LV{{ item.taskPriority }}</span
              >
              <div class="progress" v-if="item.type === 1">
                <span
                  :class="
                    item.projectStatus === 1
                      ? 'waiting'
                      : item.projectStatus === 2 && item.projectStatus === 3
                      ? 'going'
                      : 'competed'
                  "
                ></span>
                <span v-if="item.projectStatus === 1">待开始</span>
                <span v-else-if="item.projectStatus === 2">进行中</span>
                <span v-else>已结束</span>
              </div>
              <div
                class="progress"
                :class="
                  item.taskStatus === 1
                    ? 'waiting'
                    : item.taskStatus === 2 && item.taskStatus === 3
                    ? 'going'
                    : 'competed'
                "
                v-else
              >
                <span
                  :class="
                    item.taskStatus === 1
                      ? 'waiting'
                      : item.taskStatus === 2 && item.taskStatus === 3
                      ? 'going'
                      : 'competed'
                  "
                ></span>
                <span v-if="item.taskStatus === 1">未开始</span>
                <span v-else-if="item.taskStatus === 2">进行中</span>
                <span v-else>已完成</span>
              </div>
            </div>
            <div class="bottomRight">
              <span>{{ item.createTime }}</span>
            </div>
          </div>
        </div>
        <div class="right">
          <el-tooltip effect="dark" content="删除评论" placement="top">
            <img
              src="@/assets/delete.png"
              alt=""
              @click="deleteComment(item.id)"
          /></el-tooltip>
        </div>
      </div>
    </div>
    <div v-else>
      <span>暂无评论</span>
    </div>
  </div>
</template>

<script>
import { getSendComment, deleteComment } from '@/api/comment/comment.js';
export default {
  name: 'myoutput',
  data() {
    return {
      sendComment: []
    };
  },
  created() {
    this.getComment();
  },
  methods: {
    async getComment() {
      const res = await getSendComment(sessionStorage.getItem('userid'));
      console.log(res);
      this.sendComment = [...res.data.commentBVos, ...res.data.commentVoList];
    },
    deleteComment(id) {
      this.$confirm('确定删除该条评论?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(async () => {
        const res = await deleteComment({id: id});
        console.log(res);
        if (res.code === 200) {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.getComment();
        } else {
          this.$message.error('删除失败');
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  }
};
</script>

<style lang="less" scoped>
.myoutput {
  width: 100%;
  background-color: #fff;
  border-radius: 0 5px 5px 5px;
  box-shadow: 1px -2px 3px 0px rgba(153, 153, 153, 0.5),
    1px 2px 3px 0px rgba(153, 153, 153, 0.5);
  padding: 40px 20px;
  box-sizing: border-box;
  .content {
    overflow-y: scroll;
    height: 900px;
    width: 100%;
    .item {
      // width: 1809px;
      width: 99%;
      height: 120px;
      background: #ffffff;
      border: 1px solid #e6ebff;
      margin-bottom: 20px;
      padding: 10px 30px;
      padding-right: 0;
      display: flex;
      overflow-y: scroll;
      box-sizing: border-box;
      .left {
        width: 90%;
        box-sizing: border-box;
        font-size: 14px;
        border-right: 1px solid #e6ebff;
        padding-right: 30px;
        p {
          margin: 0;
          padding: 0;
        }
        .commentContent {
          font-size: 14px;
          color: #333333;
        }
        .myComment {
          font-size: 14px;
          font-weight: 400;
          color: #555555;
          margin-top: 15px;
        }
        .bottom {
          margin-top: 15px;
          display: flex;
          justify-content: space-between;
          font-weight: 400;
          color: #444444;
          .bottomLeft {
            display: flex;
            align-items: center;
            .spanStyle {
              width: 5px;
              height: 15px;
              background: linear-gradient(180deg, #1160cf 0%, #cd06bf 100%);
              border-radius: 3px;
              margin-right: 5px;
            }
            .span {
              display: inline-block;
            }
            .projectName {
              margin-right: 30px;
            }
            // .level{
            //   margin-right: 30px;
            // }
            .LvOne {
              text-align: center;
              color: white;
              border-radius: 10px;
              width: 60px;
              height: 20px;
              margin-right: 30px;
              background: #c5f5d1;
            }
            .LvTwo {
              text-align: center;
              color: white;
              border-radius: 10px;
              width: 60px;
              height: 20px;
              margin-right: 30px;
              background: #f7cbd2;
            }
            .LvThree {
              text-align: center;
              color: white;
              border-radius: 10px;
              width: 60px;
              height: 20px;
              margin-right: 30px;
              background: #cbd5f5;
            }
            .progress {
              span {
                display: inline-block;
              }
              .waiting {
                width: 10px;
                height: 10px;
                border-radius: 50%;
                background-color: #555555;
              }
              .going {
                width: 10px;
                height: 10px;
                border-radius: 50%;
                background-color: #ffd167;
              }
              .competed {
                width: 10px;
                height: 10px;
                border-radius: 50%;
                background-color: #3ea528;
              }
            }
            .progress.waiting {
              color: #555555;
            }
            .progress.going {
              color: #ffd167;
            }
            .progress.competed {
              color: #3ea528;
            }
          }
        }
      }
      .right {
        width: 200px;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        img {
          height: 40px;
          width: 40px;
          // line-height: ;
        }
      }
    }
  }
}
</style>
